package euler;

import java.util.ArrayList;
import java.util.List;

public class Phi extends ArrayList<Double> {

    public Phi(int Nmax) {
        PrimeFactors pfactors;
        double phi = 1;
        for (int n = 1 ; n <= Nmax ; n++) {
            pfactors = new PrimeFactors(n);
            for (Double p : pfactors.singlefactors()) {
                phi = phi * (1 - 1 / p);
            }
            phi = phi * n;
            add(phi);
            phi = 1;
        }
    }

    public List<Integer> intValues() {
        List<Integer> ret = new ArrayList<Integer>();
        for (Double D : this) {
            ret.add(D.intValue());
        }
        return ret;
    }
}


